import * as index from '@/api/index.js'
import Select from '@/components/select/select.vue'
import HomeList from '@/components/homeList/homeList.vue'
import seekList from '@/components/seekList.vue'
import imageLabel from '@/components/imageLabel/index.vue'
export default {
	components: {
		Select,
		HomeList,
		seekList,
		imageLabel
	},
	data() {
		return {
			NavHeight: this.NavHeight,
			swiperUrl: [], //轮播图
			btnList: [
				// {
				// 	imgUrl: '/static/home/btn1.png',
				// 	title: '租房',
				// },
				// {
				// 	imgUrl: '/static/home/btn2.png',
				// 	title: '新房',
				// 	id: 4
				// },
				// {
				// 	imgUrl: '/static/home/btn3.png',
				// 	title: '二手房',
				// 	id: 5
				// },
				// {
				// 	imgUrl: '/static/home/btn4.png',
				// 	title: '商铺办公',
				// 	id: 3
				// }
			], //筛选
			homeList: [], //列表数据
			List: [],
			form: {
				page: 1,
				areas_id: 0,
				configure_id: [0],
				page: 1,
				rent_id: 0,
				tentype_id: 0,
				size_id: [0],
				// type: 1
			}, //查询条件
			seekForm: {
				type: '',
				page: 1,
			},
			tableList: [
				{
					name: '租房',
					type: 1
				}, {
					name: '新房',
					tentype_id: 4
				},
				{
					name: '二手房',
					tentype_id: 5
				},

				{
					name: '商铺办公',
					tentype_id: 3
				},
				{
					name: '求租',
					type: 1
				},
				{
					name: '求购',
					type: 2
				}
			],
			title: {},
			status: 'nomore',
			bottom: '',
			tableIndex: 0
		}
	},

	onShow() {
		this.getSwiper()
		this.getList()
		this.getMenu()
		this.getTeneList()
	},
	onLoad(option) {
		let that = this
		uni.$on('form', function(data) {
			that.homeList = []
			that.form = data
			that.form.page = 1
			that.getList()
		})
		// this.getUserinfo()
	},
	onReachBottom() {
		// this.homeList=[]
		if (this.tableIndex <= 3) {
			this.form.page += 1
			this.getList()
		} else {
			this.seekForm.page += 1
			this.getseekList()
		}
	},
	onPullDownRefresh() {
		this.form.page = 1
		this.seekForm.page = 1
		if (this.tableIndex <= 3) {
			this.homeList = []
			this.getList()
		} else {
			this.List = []
			this.getseekList()
		}

	},
	onShareAppMessage() {
		const promise = new Promise(resolve => {
			setTimeout(() => {
				resolve({
					title: '租房\买房\卖房\出租信息大全，快来看看～'
				})
			}, 200)
		})
		return {
			title: '租房\买房\卖房\出租信息大全，快来看看～',
			path: '/pages/home/index',
			promise
		}
	},
	methods: {
		getTeneList(){
			index.getTeneList().then(res=>{
				console.log(res,'resdata');
				this.btnList = res.data
			})
		},
		// 获取轮播图
		getSwiper() {
			index.swiperList().then(res => {
				this.swiperUrl = res.data
			})
		},
		queryTo(item) {
			// if(item.id){
			console.log(item)
			uni.setStorage({
				key: 'types',
				data: item,
				success: function() {}
			});
				uni.navigateTo({
					url: `/pages/home/query/query`
				});
			// if (item.type == '1') {
			// 	uni.navigateTo({
			// 		url: `/pages/home/query/query`
			// 	});
			// } else {
			// 	uni.navigateTo({
			// 		url: `/pages/home/queryRent/query`
			// 	});
			// }

			// }
			// else{
			// 	uni.showToast({
			// 		icon:'none',
			// 		title: '正在开发,敬请期待',
			// 		duration: 2000
			// 	});
			// }
		},
		// 轮播图跳转
		webView(item) {
			if (item.link == 1 || item.conteng == 1) {
				this.$tools.navigate(`/pages/home/webView/webView?id=${item.id}`)
			}
		},
		getList() {
			// uni.showLoading({
			// 	title: '加载中'
			// });
			let form = this.form
			var objString = JSON.stringify(form);
			var obj2 = JSON.parse(objString);
			obj2.configure_id = obj2.configure_id.join()
			obj2.size_id = obj2.size_id.join()
			index.getList(obj2).then(res => {
				// this.homeList.push(...res.data.data)
				if (this.form.page >= res.lalast_page) {
					return
				}
				this.status = 'loading'
				if (this.form.page == 1) {
					this.homeList = res.data.data
				} else {
					this.homeList = this.homeList.concat(res.data.data);
				}
				this.form.page = res.data.current_page + 1
				// this.homeList=res.data.data
				this.status = 'nomore'
				uni.hideLoading();
				console.log(this.homeList);
			}).catch(err => {
				uni.hideLoading();
			})
			uni.stopPullDownRefresh()
		},
		getseekList() {
			// uni.showLoading({
			// 	title: '加载中'
			// });
			index.getWantList(this.seekForm).then(res => {
				this.List.push(...res.data.data)
				uni.hideLoading();
			}).catch(err => {
				uni.hideLoading();
			})
		},
		getMenu() {
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			this.bottom = menuButtonInfo.bottom
		},
		tableClick(item, index) {
			this.tableIndex = index
			this.form.page = 1
			this.seekForm.page = 1
			if (index <= 3) {
				if (item.tentype_id) {
					this.form.type = ''
					this.form.tentype_id = item.tentype_id
					this.getList()
				} else {
					this.form.tentype_id = ''
					this.form.type = item.type
					this.getList()
				}
			} else {
				this.List = []
				this.seekForm.type = item.type
				this.getseekList()
			}
		}

	}
}
